import { t } from 'i18next'
import React from 'react'
import {
	IconStatusDcs,
	IconStatusDoubleFlow,
	IconStatusMix,
	IconStatusOffline,
	IconStatusPoll,
	IconStatusRec,
	IconStatusSelect,
	IconStatusTVWall,
	IconStatusUpMt,
	IconStatusVmp,
} from '../../../../components'
import { statusType } from './utils'
import { IMcc } from '@/api/manager/type'
import { useMccStore } from '@/pages/manager/store'
import { usePollStore } from '@/pages/manager/blocks/poll/store'

type StatusComponentType = Record<statusType | 'offline', (mcc: IMcc) => React.ReactNode>

const Vmp = ({ mcc }: { mcc: IMcc }) => {
	if (!mcc.isMt) return null
	return <IconStatusVmp isOn={mcc.status.isVmp} title={t('画面合成')} />
}
const Mix = ({ mcc }: { mcc: IMcc }) => {
	const mixMode = useMccStore((state) => state.mixMode)
	if (!mcc.isMt) return null
	const title = mixMode === 0 ? t('混音') : mixMode === 2 ? t('定制混音') : t('智能混音')
	return <IconStatusMix isOn={mcc.status.isMix} title={title} />
}
const Poll = ({ mcc }: { mcc: IMcc }) => {
	const isOpenMeetingPoll = useMccStore((state) => state.curPage === 'meeting_poll')
	const activePollingMts = usePollStore((state) => state.activePollingMts)
	if (!mcc.isMt) return null
	let isActivePolling = false
	let isInMeetingPollList = false
	if (isOpenMeetingPoll) {
		for (const item of activePollingMts) {
			if (item.mtKey === mcc.mtKey) {
				isInMeetingPollList = true
				isActivePolling = item.isActive
			}
		}
	}
	return <IconStatusPoll isOn={mcc.status.isPoll || isInMeetingPollList} active={isActivePolling} title={t('轮询')} />
}
const Dcs = ({ mcc }: { mcc: IMcc }) => {
	if (!mcc.isMt) return null
	return <IconStatusDcs isOn={mcc.status.isDcs} title={t('数据协作')} />
}
export const StatusIconComponent: StatusComponentType = {
	vmp: (mcc) => <Vmp mcc={mcc} key="vmp" />,
	mix: (mcc) => <Mix mcc={mcc} key="mix" />,
	poll: (mcc) => <Poll mcc={mcc} key="poll" />,
	dcs: (mcc) => <Dcs mcc={mcc} key="dcs" />,
	select: (mcc) => <IconStatusSelect key="select" title={t('终端选看')} />,
	tvWall: (mcc) => <IconStatusTVWall key="tvWall" title={t('电视墙')} />,
	upMt: (mcc) => <IconStatusUpMt key="upMt" title={t('上传')} />,
	rec: (mcc) => <IconStatusRec key="rec" title={t('终端录像')} />,
	doubleFlow: (mcc) => <IconStatusDoubleFlow key="doubleFlow" title={t('内容共享')} />,
	offline: (mcc) => <IconStatusOffline key="offline" title={t('离线')} />,
}
